
package com.lczyfz.campusinfo.modules.frontuser.entity;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.google.common.collect.Lists;

import com.lczyfz.campusinfo.common.config.Global;
import com.lczyfz.campusinfo.common.persistence.DataEntity;
import com.lczyfz.campusinfo.common.utils.excel.annotation.ExcelField;
import com.lczyfz.campusinfo.common.utils.excel.fieldtype.RoleListType;
import com.lczyfz.campusinfo.modules.sys.entity.Role;
import org.hibernate.validator.constraints.Email;
import org.hibernate.validator.constraints.Length;

import java.util.Date;
import java.util.List;

/**
 * 前端用户管理Entity
 *
 * @author yt
 * @version 2017-10-26
 */
public class CampusinfoFrontUser extends DataEntity<CampusinfoFrontUser> {

    private static final long serialVersionUID = 1L;
    private String loginName;        // 登录名
    private String password;        // 密码
    private String name;        // 姓名
    private String email;        // 邮箱
    private String phone;        // 电话
    private String mobile;        // 手机
    private String userType;        // 用户类型
    private String loginIp;        // 最后登陆IP
    private Date loginDate;        // 最后登陆时间
    private String loginFlag;        // 是否可登录

    private String photo;    // 头像

    private String oldLoginName;// 原登录名
    private String newPassword;    // 新密码


    // TODO 根据角色查询用户条件
    private Role role;    // 根据角色查询用户条件

    // TODO 添加拥有角色列表
    private List<Role> roleList = Lists.newArrayList(); // 添加拥有角色列表

    public CampusinfoFrontUser() {
        super();
        this.loginFlag = Global.YES;
    }

    public CampusinfoFrontUser(String id) {
        super(id);
    }

    // TODO 添加带参数 loginName 构造器
    // 添加带参数 loginName 构造器
    public CampusinfoFrontUser(String id, String loginName) {
        super(id);
        this.loginName = loginName;
    }

    // TODO 添加带参数 role 构造器
    public CampusinfoFrontUser(Role role) {
        super();
        this.role = role;
    }

    // TODO 添加拥有角色列表
    // 添加拥有角色列表
    @JsonIgnore
    @ExcelField(title = "拥有角色", align = 1, sort = 800, fieldType = RoleListType.class)
    public List<Role> getRoleList() {
        return roleList;
    }

    public void setRoleList(List<Role> roleList) {
        this.roleList = roleList;
    }

    // TODO
    @JsonIgnore
    public List<String> getRoleIdList() {
        List<String> roleIdList = Lists.newArrayList();
        for (Role role : roleList) {
            roleIdList.add(role.getId());
        }
        return roleIdList;
    }

    // TODO
    public void setRoleIdList(List<String> roleIdList) {
        roleList = Lists.newArrayList();
        for (String roleId : roleIdList) {
            Role role = new Role();
            role.setId(roleId);
            roleList.add(role);
        }
    }

    // TODO 根据角色查询用户条件
    // 根据角色查询用户条件
    public Role getRole() {
        return role;
    }

    public void setRole(Role role) {
        this.role = role;
    }


    @Length(min = 1, max = 100, message = "登录名长度必须介于 1 和 100 之间")
    public String getLoginName() {
        return loginName;
    }

    public void setLoginName(String loginName) {
        this.loginName = loginName;
    }

    // TODO @JsonIgnore
    @JsonIgnore
    @Length(min = 1, max = 100, message = "密码长度必须介于 1 和 100 之间")
    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    @Length(min = 0, max = 100, message = "姓名长度必须介于 0 和 100 之间")
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Email(message = "邮箱格式不正确")
    @Length(min = 0, max = 200, message = "邮箱长度必须介于 0 和 200 之间")
    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    @Length(min = 0, max = 200, message = "电话长度必须介于 0 和 200 之间")
    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    @Length(min = 0, max = 200, message = "手机长度必须介于 0 和 200 之间")
    public String getMobile() {
        return mobile;
    }

    public void setMobile(String mobile) {
        this.mobile = mobile;
    }

    @Length(min = 0, max = 1, message = "用户类型长度必须介于 0 和 1 之间")
    public String getUserType() {
        return userType;
    }

    public void setUserType(String userType) {
        this.userType = userType;
    }

    public String getLoginIp() {
        return loginIp;
    }

    public void setLoginIp(String loginIp) {
        this.loginIp = loginIp;
    }

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    public Date getLoginDate() {
        return loginDate;
    }

    public void setLoginDate(Date loginDate) {
        this.loginDate = loginDate;
    }

    public String getLoginFlag() {
        return loginFlag;
    }

    public void setLoginFlag(String loginFlag) {
        this.loginFlag = loginFlag;
    }

    public String getPhoto() {
        return photo;
    }

    public void setPhoto(String photo) {
        this.photo = photo;
    }

    public String getOldLoginName() {
        return oldLoginName;
    }

    public void setOldLoginName(String oldLoginName) {
        this.oldLoginName = oldLoginName;
    }

    public String getNewPassword() {
        return newPassword;
    }

    public void setNewPassword(String newPassword) {
        this.newPassword = newPassword;
    }
}